package com.yunxi.controller.otd;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.otd.pojo.MonthPlanDetailVO;
import com.yunxi.otd.pojo.MonthPlanImportDTO;
import com.yunxi.otd.pojo.MonthPlanVO;
import com.yunxi.otd.service.MonthPlanDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 月度需求计划 前端控制器
 * </p>
 *
 * @author XUQI
 * @since 2019-05-06
 */
@RestController
@RequestMapping("/admin/otd/month")
@Api(tags = "OTD:MonthPlan", description = "月度需求计划")
public class MonthPlanController {

    private static final Logger logger = LoggerFactory.getLogger(MonthPlanController.class);

    //    @Reference(version = "${demo.service.version}",
//        application = "${dubbo.application.id}",
//        registry = "${dubbo.registry.address}",
//        url = "${dubbo.application.url}",
//        check = false,
//        timeout = 1000000000
//    )
    @Autowired
    MonthPlanDubboService monthPlanDubboService;

    /**
     * 分页查询月度生产计划
     *
     * @param monthPlanVO VO
     * @param pageNum 页数
     * @param pageSize 行数
     * @return ApiResult
     */
    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    public ApiResult page(MonthPlanVO monthPlanVO, Integer pageNum, Integer pageSize) {
        return ResponseUtil.ok(monthPlanDubboService.pageByVo(monthPlanVO, pageNum, pageSize));
    }

    /**
     * 根据月度计划单号查询明细
     *
     * @param monthPlanVO VO
     * @return ApiResult
     */
    @GetMapping("/detail")
    @ApiOperation(value = "根据月度计划编号查询明细")
    public ApiResult findDetailByCode(MonthPlanVO monthPlanVO) {
        return ResponseUtil.ok(monthPlanDubboService.findMonthPlanDetailByCode(monthPlanVO.getMonthPlanCode()));
    }

    /**
     * 更新月度生产计划明细
     *
     * @param detailVO VO
     * @return ApiResult
     */
    @PostMapping("/modify")
    @ApiOperation(value = "更新月度生产计划")
    public ApiResult modifyMonthPlan(@RequestBody MonthPlanDetailVO detailVO, @CurrentUser LoginInfo info) {
        return monthPlanDubboService.modifyMonthPlanDetail(detailVO, info);
    }

    /**
     * 导入月度生产计划
     *
     * @param importDTO DTO
     * @param info 用户
     * @return ApiResult
     */
    @PostMapping("/import")
    @ApiOperation(value = "导入月度生产计划")
    public ApiResult addMonthPlan(@RequestBody MonthPlanImportDTO importDTO, @CurrentUser LoginInfo info) {
        return monthPlanDubboService.importMonthPlan(importDTO, info);
    }


    /**
     * 下发月度计划
     *
     * @param monthPlanId id
     * @param info 用户
     * @return ApiResult
     */
    @PostMapping("/send")
    @ApiOperation(value = "下发月度生产订单")
    public ApiResult sendMonthPlan(@RequestBody String monthPlanId, @CurrentUser LoginInfo info) {
        return monthPlanDubboService.sendMonthPlan(monthPlanId, info);
    }
}
